import { defineStore } from "pinia";
import categoryApi, {type categoryParamsData} from "@/api/category";

export const categoryStore = defineStore('category',{
    state:():any=>{
        return{
          categoryList:{},
          categoryItem:{},
          itemList:{},
          category1Id:0
        }
    },
    actions:{
      async getCategoryList (categoryParams:categoryParamsData){
        try {
            const result  = await categoryApi.getCategory(categoryParams)
            //  console.log('result', result)
            this.categoryList = result
        } catch (error) {
            return Promise.reject(error)
        }
      },
      //右边列表
      async getCategoryItem (categoryId:number){
        try {
            const result  = await categoryApi.getCategoryItem(categoryId)
            console.log('result1', result)
            this.categoryItem = result
        } catch (error) {
            return Promise.reject(error)
        }
      },
      //点击分类下列表
      async getCategoryItemList(subCategoryId:number,categoryId:number){
        try {
          const result =  await categoryApi.getCategoryList(subCategoryId,categoryId)
          // console.log('result3',result);
          this.itemList = result
        } catch (error) {
          return Promise.reject(error)
        }
      }
    },
    getters:{}
})